package com.woniuxy.provider.student.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.common.entity.Student;
import com.woniuxy.provider.student.mapper.StudentMapper;
import com.woniuxy.provider.student.service.StudentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: linKe
 * @Date: 2022/1/19 15:12
 * @FileName: StudentServiceImpl
 * @version: 1.0
 * @Description: 描述
 */
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper,Student> implements StudentService {
    @Resource
    StudentMapper studentMapper;

    /**
     * 根据id、 查询
     * @param id id值
     * @return  结果
     */
    @Override
    public Student getStudent(int id) {
        return studentMapper.selectById(id);
    }

    @Override
    public int updateStudent(Student student) {
        LambdaUpdateWrapper<Student> lambdaUpdateWrapper = new LambdaUpdateWrapper<Student>();

        lambdaUpdateWrapper.eq(Student::getId, student.getId()).set(Student::getAge, student.getAge());

        return studentMapper.update(null, lambdaUpdateWrapper);
    }

    @Override
    public int addStudent(Student student) {
        return studentMapper.insert(student);
    }


    @Override
    public List<Student> getStudentList() {
        return studentMapper.selectList(null);
    }

    @Override
    public int deleteStudent(int id) {
        return studentMapper.deleteById(id);
    }


}
